package com.xjl.everyinterview.datastructureandalgorithm.algorithm.sort.countsort;

/**
 * @author xjl
 * @version 1.0
 * @description: 计数排序  根据数据的下标来统计个数
 * 适用于范围有限的数据
 * 例如 年龄，月，星期等
 * @date 2021/8/23 16:24
 */
public class Test {


    public static void main(String[] args) {
        int[] count = {1, 2, 3, 4, 2, 1, 3, 2, 3, 5, 6, 7, 8, 6, 5, 4, 5, 6, 4, 9, 0, 0, 22, 0, 0};
        int max = 0;
        //得到最大值
        for (int i = 0; i < count.length - 1; i++) {
            if (count[i] > count[i + 1]) {
                max = count[i];
            }
        }
        CountSort countSort = new CountSort(count,max);
        int[] sort = countSort.sort();
        for (int i = 0; i < sort.length; i++) {
            int i1 = sort[i];
            System.out.println(i + "=" + i1);

        }
    }
}
